home *** CD-ROM | disk | FTP | other *** search
- Path: templar.fgi.net!bwendlin
- From: bwendlin@I_should_put_my_domain_in_etc_NNTP_INEWS_DOMAIN (Bill Wendling)
- Newsgroups: comp.lang.c
- Subject: Re: File Open Problem - Please provide clues
- Date: 31 Mar 1996 08:24:47 GMT
- Organization: FGInet, Inc., Springfield, IL
- Distribution: world
- Message-ID: <4jlfgf$59u@grail.fgi.net>
- References: <4jkq8h$1it6@useneta1.news.prodigy.com>
- NNTP-Posting-Host: templar.fgi.net
- X-Newsreader: TIN [version 1.2 PL2]
-
- Steve Bailey inexplicably wrote:
-
- } Hi I'm having problems with opening files which are named
- } after simple numbers:
- } 2
- } 5, etc.
- } The reason for naming them this way is because I'm writing a
- } program in C that increments a number, and then attempts to
- } open the file that's actually named by that number.
- } I get mismatched type errors when using FOPEN:
- } int num;
- } filepointer = FOPEN(num,"r"); or
- } filepointer = FOPEN("num","r");
-
- Try:
- int num;
- char file[255];
-
- sprintf(file, "%d", num);
- filepointer = fopen(file, "r");
-
- or something similar to this.
-
- } Is there a way to manipulate an integer: store it in integer
- } variables, arrays, etc.., but then use that integer to open
- } a file actually named by that integer?..
- } I was going to name the files:
- } 0.txt, 1.txt, 2.txt,
-
- With the above example, you could just do:
- sprintf(file, "%d.txt", num);
-
- } and so forth, but this was even trickier with the string
- } concatenating, (attached ".txt" to it) etc.. so the files
- } are named after numbers simply..
- }
- } any help appreciated.
- } Steve
-
- --
- Bill Wendling bwendlin@fgi.net
- GCS/M/S d s-:+ a? C++++$ UL++>++++ P+++>+++++ L+++>+++++ E--- W-- N++ !o
- !K w--- O M-- !V PS+++@ PE- Y !PGP t+++(*) 5-- X- R++ tv--- b+++ DI++++
- !D G+ e++>+++++ h(++) !r !y+
-